package com.mg.smarttask.client;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.ClickEvent;

public class Login extends Composite {
	LoginModule loginModule;
	public Login(LoginModule module) {
		loginModule = module;
		VerticalPanel verticalPanel = new VerticalPanel();
		verticalPanel.setStyleName("loginPanel");
		initWidget(verticalPanel);
		verticalPanel.setSize("450px", "250px");
		
		Label titleLabel = new Label("Connexion \u00E0 votre compte");
		titleLabel.setStyleName("h2");
		verticalPanel.add(titleLabel);
		titleLabel.setHeight("30");
		
		final Label error = new Label("");
		error.setStyleName("error");
		verticalPanel.add(error);
		error.setHeight("30px");
		
		FlexTable flexTable = new FlexTable();
		flexTable.setStyleName("gwt-FlexTable");
		verticalPanel.add(flexTable);
		flexTable.setSize("100%", "122px");
		
		Label lblUsername = new Label("Login");
		flexTable.setWidget(0, 0, lblUsername);
		flexTable.getCellFormatter().setHeight(0, 0, "50px");
		flexTable.getCellFormatter().setWidth(0, 0, "130px");
		lblUsername.setWidth("80px");
		
		final TextBox usernameBox = new TextBox();
		flexTable.setWidget(0, 1, usernameBox);
		usernameBox.setSize("90%", "30px");
		
		Label lblPassword = new Label("Mot de passe");
		flexTable.setWidget(1, 0, lblPassword);
		flexTable.getCellFormatter().setHeight(1, 0, "50px");
		flexTable.getCellFormatter().setWidth(1, 0, "130px");
		lblPassword.setWidth("80px");
		
		final PasswordTextBox passwordBox = new PasswordTextBox();
		passwordBox.setStyleName("gwt-TextBox");
		flexTable.setWidget(1, 1, passwordBox);
		passwordBox.setSize("90%", "30px");
		
		CheckBox chckbxRemeberMeOn = new CheckBox("Se souvenir de moi");
		chckbxRemeberMeOn.setStyleName("gwt-Label");
		flexTable.setWidget(2, 1, chckbxRemeberMeOn);
		
		Button btnSeConnecter = new Button("Se connecter");
		btnSeConnecter.setStyleName("connectButton");
		btnSeConnecter.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				if(usernameBox.getText().length()==0 || passwordBox.getText().length()==0){
					error.setText("Mauvais login ou mot de passe");
				} else {
					error.setText("");
				}
			}
		});
		flexTable.setWidget(3, 1, btnSeConnecter);
		btnSeConnecter.setSize("100px", "25px");
	}

}
